import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Text示例',
      home: Scaffold(
        appBar: AppBar(title: Text('Text Widget示例')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // 3.1.1 Text基础用法
              Text("Hello world", textAlign: TextAlign.left),
              Text(
                "Hello world! I'm Jack. " * 4,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
              Text("Hello world", textScaleFactor: 1.5),

              SizedBox(height: 20),

              // 3.1.2 TextStyle样式
              Text(
                "Hello world",
                style: TextStyle(
                  color: Colors.blue,
                  fontSize: 18.0,
                  height: 1.2,
                  fontFamily: "Courier",
                  background: Paint()..color = Colors.yellow,
                  decoration: TextDecoration.underline,
                  decorationStyle: TextDecorationStyle.dashed,
                ),
              ),

              SizedBox(height: 20),

              // 3.1.4 DefaultTextStyle默认样式
              DefaultTextStyle(
                style: TextStyle(color: Colors.red, fontSize: 20.0),
                child: Column(
                  children: [
                    Text("hello world"),
                    Text("I am Jack"),
                    Text(
                      "I am Jack",
                      style: TextStyle(
                        inherit: false, // 不继承默认样式
                        color: Colors.grey,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
